﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Scripts.RCPKit
{
    public class Guild
    {
        public int GuildID;
        public string GuildName;
        public string GuildMOTD;
        public List<GuildMember> GuildMembers;

        public Guild()
        {
        
        }

        public Guild(string GuildName)
        {
            SetGuildByString(GuildName);
        }

        public Guild(int guildID, string guildName, string guildMOTD, List<GuildMember> guildMembers)
        {
            GuildID = guildID;
            GuildName = guildName;
            GuildMOTD = guildMOTD;
            GuildMembers = guildMembers;
        }

        public bool SetGuildByString(string name)
        {
            if (DatabaseSettings.DatabaseProvider == DatabaseType.SQLite)
            {
               Guild temp = GuildDataSQLite.GetGuildByName(name);
                if(temp != null)
                {
                    this.GuildID = temp.GuildID;
                    this.GuildName = temp.GuildName;
                    this.GuildMOTD = temp.GuildMOTD;
                    this.GuildMembers = temp.GuildMembers;
                    return true;
                }
                else
                    return false;
            }
            else if (DatabaseSettings.DatabaseProvider == DatabaseType.MySQL)
            {
            
            }
            else
                return false;
        }

        public static List<GuildMember> DerializeMembers(string SerializedMembers)
        {
            List<string> guildMemberNames = new List<string>(SerializedMembers.Split(','));
            List<GuildMember> GuildMembers = new List<GuildMember>();
            foreach (string s in guildMemberNames)
            {
                string[] t = s.Split('|');
                GuildMembers.Add(new GuildMember(t[0],Int32.Parse(t[1])));
            }
            return null;
        }

        public static string SerializeMembers (List<string> GuildMembers)
        {
            return null;
        }
    }
}
